import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		count: 0,
		todos: [
		  {id: 1, text: '111', done: true },
		  {id: 2, text: '222', done: false},
		  {id: 3, text: '333', done: true},
		  {id: 4, text: '444', done: false}
		]
	},
	getters: {
		doneTodos: state => {
			return state.todos.filter(todo => todo.done)
		},
		undoneTodos: state => {
			return state.todos.filter(todo => !(todo.done))
		},
		doneTodosCount: (state, getters) => {
			return getters.doneTodos.length
		}
	},
	mutations: {
		increment: state => state.count++,
		decrement: state => state.count--
	}
});

export default store;